package com.asf.sofom.repository;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;

import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.asf.sofom.domain.OAuthorities;

@Repository(value="authoritiesDao")
public class JPAAuthorities implements AuthoritiesDao{

	private EntityManager em = null;
	
	@PersistenceContext
	public void setEntityManager(EntityManager em){
		this.em = em;
	}
	
	@Transactional(readOnly = true)
	@SuppressWarnings("unchecked")		
	public List<OAuthorities> getAuthorities() {
		TypedQuery<OAuthorities> tq = (TypedQuery<OAuthorities>) em.createNativeQuery("Select * from authorities", OAuthorities.class);
		List<OAuthorities> la = tq.getResultList();
		return la;
	}

	@Transactional(readOnly = false)
	public void setAuthorities(OAuthorities auth) {
		em.merge(auth);
	}

}
